package com.aloda.ojquestion.pojo.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.aloda.ojcommon.domain.entity.JudgeCase;
import com.aloda.ojcommon.domain.entity.JudgeConfig;
import com.aloda.ojcommon.domain.entity.Question;
import com.aloda.ojquestion.pojo.entity.QuestionPrompt;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author aloda
 * @Date 2025/4/26 9:09
 */
@Data
public class QuestionInfoVO {

    /**
     * id
     */
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 标签列表（json 数组）
     */
    private List<String> tags;

    /**
     * 题目预设代码
     */
    private List<QuestionPrompt> prompt;

    /**
     * 题目答案
     */
    private String answer;

    /**
     * 题目提交数
     */
    private Integer submitNum;

    /**
     * 题目通过数
     */
    private Integer acceptedNum;

    /**
     * 判题用例（json 数组）
     */
    private List<JudgeCase> judgeCase;

    /**
     * 判题配置（json 对象）
     */
    private JudgeConfig judgeConfig;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    public static QuestionInfoVO of(Question question) {
        QuestionInfoVO questionInfoVO = BeanUtil.toBeanIgnoreError(question, QuestionInfoVO.class);
        questionInfoVO.setTags(JSONUtil.toList(question.getTags(), String.class));
        questionInfoVO.setJudgeCase(JSONUtil.toList(question.getJudgeCase(), JudgeCase.class));
        questionInfoVO.setJudgeConfig(JSONUtil.toBean(question.getJudgeConfig(), JudgeConfig.class));
        questionInfoVO.setPrompt(JSONUtil.toList(question.getPrompt(), QuestionPrompt.class));
        return questionInfoVO;
    }
}
